﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

namespace CustomerOrderingSystem
{
    class sql_order
    {
        public static DataTable QueryDataTable(string sql)
        {
            string _sql = " select * from Orders where 1=1" + sql;
            SqlConnection conn = Sql.d();
            SqlDataAdapter sda = new SqlDataAdapter(_sql, conn);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            DataTable DT = ds.Tables[0];
            return DT;
        }
        public static DataTable QueryDataTable0()
        {
            return QueryDataTable(null);


        }
        public static int QueryDataTable1(string sql)
        {
            string _sql = "select count(*) from Orders where Ono='" + sql + "'";
            SqlConnection conn = Sql.d();
            conn.Open();
            SqlCommand cmd = new SqlCommand(_sql, conn);
            int count = (int)cmd.ExecuteScalar();
            return count;

        }

        public static void QueryDataTable2(string sq1a, string sq1b, string sq1c, string sq1d)
        {
            string _sql = "update Orders set Cno ='" + sq1a + "',Gno='" + sq1b + "',Gnum='" + sq1c + "'where Ono='" + sq1d + "'";
            SqlConnection conn = Sql.d();
            conn.Open();
            SqlCommand cmd = new SqlCommand(_sql, conn);
            cmd = new SqlCommand(_sql, conn);
            cmd.ExecuteNonQuery();
        }

        public static void QueryDataTable3(string sq1a, string sq1b, string sq1c, string sq1d)
        {
            string _sql = "insert into Orders values('" + sq1a + "','" + sq1b + "','" + sq1c + "','" + sq1d + "')";
            SqlConnection conn = Sql.d();
            conn.Open();
            SqlCommand cmd = new SqlCommand(_sql, conn);
            cmd = new SqlCommand(_sql, conn);
            cmd.ExecuteNonQuery();
        }
        public static void QueryDataTable4()
        {
            SqlConnection conn = Sql.d();
            conn.Close();
        }
        public static int QueryDataTable5(string sql)
        {
            string _sql = "delete from Orders where Ono='" + sql + "'";
            SqlConnection conn = Sql.d();
            SqlCommand cmd = new SqlCommand(_sql, conn);
            conn.Open();
            int rows = cmd.ExecuteNonQuery();
            return rows;
        }
    }
}
